#include <iostream>
#include <string>
#include <memory>
#include <list>

using namespace std;

/*
\ brief:   过滤器接口
\ author: 清晨与猫鱼
*/
class Filter {
public:
    virtual void execute(string request) = 0;
};

/*
\ brief:   身份验证过滤
\ author: 清晨与猫鱼
*/
class AuthenticationFilter 
    : public Filter {
public:
    void execute(string request) {
        cout << "Authenticating request: " << request << endl;
    }
};


/*
\ brief:  调式过滤
\ author: 清晨与猫鱼
*/
class DebugFilter 
    : public Filter {
public:
    void execute(string request) {
        cout << "request log: " << request << endl;
    }
};


/*
\ brief:  目标
\ author: 清晨与猫鱼
*/
class Target {
public:
    void execute(string request) {
        cout << "Executing request: " << request << endl;
    }
};



/*
\ brief:  过滤链
\ author: 清晨与猫鱼
*/
class FilterChain {
public:
    void addFilter(Filter* filter) {
        filters_.emplace_back(filter);
    }

    void execute(string request) {
        for (unique_ptr<Filter>& filter : filters_) {
            filter->execute(request);
        }

        target_->execute(request);
    }

    void setTarget(Target* target) {
        target_.reset(target);
    }
private:
    unique_ptr<Target> target_;
    list<unique_ptr<Filter>> filters_;
};



/*
\ brief:  过滤管理
\ author: 清晨与猫鱼
*/
class FilterManager {
public:
    explicit FilterManager(Target* target) {
        filterChain_.setTarget(target);
    }

    void setFilter(Filter* filter) {
        filterChain_.addFilter(filter);
    }

    void filterRequest(string request) {
        filterChain_.execute(request);
    }
private:
    FilterChain filterChain_;
};


/*
\ brief:  客户端
\ author: 清晨与猫鱼
*/
class Client {
public:
    void setFilterManager(FilterManager* filterManager) {
        filterManager_.reset(filterManager);
    }

    void sendRequest(string request) {
        filterManager_->filterRequest(request);
    }
private:
    unique_ptr<FilterManager> filterManager_;
};